
// 分辨率转换工具类，banner 16:9，商品图片 4:3

// 根据屏幕计算出应的宽高
function getResolutionRatio(type, padding = 0) {
    // getSystemInformSync 获取系统信息同步接口 已经弃用getWindowInfo
  const systemInfo = wx.getWindowInfo();
  const screenWidth = systemInfo.screenWidth;
  let realWidth = screenWidth - padding;
  let ratio = 0;
  if (type === 'banner') {
    ratio = 16 / 9;
    // banner 宽度为屏幕宽度，高度根据比例计算
    const bannerHeight = realWidth / ratio;
    return {
      width: realWidth,
      height: bannerHeight,
    };
  } else if (type === 'product') {
    ratio = 4 / 3;
    // 商品图片宽度为屏幕宽度，高度根据比例计算
    const productHeight = realWidth / ratio;
    return {
      width: realWidth,
      height: productHeight,
    };
  } else {
    ratio = 1;
    const height = realWidth / ratio;
    // 其他情况宽度为屏幕宽度，高度为屏幕高度
    return {
      width: realWidth,
      height,
    };
  }
}

// 获取状态栏的高度
function getStatusBarHeight() {
  try {
    const systemInfo = wx.getWindowInfo();
    return systemInfo.statusBarHeight || 0;
  } catch (error) {
    console.error('获取状态栏高度失败:', error);
    // 返回默认值，iOS通常44px，Android通常24px
    return 44;
  }
}

// 获取胶囊按钮的尺寸
function getMenuBarRect() {
  // getMenuButtonBoundingClientRect
  try {
    const rect = wx.getMenuButtonBoundingClientRect();
    return rect;
  } catch (error) {
    return {
      width: 0,
      height: 0,
      left: 0,
      right: 0,
      bottom: 0,
      right: 0
    };
  }
}

export { getResolutionRatio, getStatusBarHeight, getMenuBarRect };
